﻿using Cxuu.Common;
using Cxuu.Models;
using PetaPoco;
using System.Threading.Tasks;

namespace Cxuu.Repository
{
    [AppService]
    public class NoticeRepository : BaseRepository<Notice, PetaPocoContext>
    {
        public NoticeRepository(PetaPocoContext petaPocoContext) : base(petaPocoContext) { }

        /// <summary>
        /// 查询一条
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task<ViewNotice> GetAndUserAsync(int id)
        {
            Sql sql = Sql.Builder;
            sql.Select("notice.*,user.Nickname,user.Avatar")
                .From("cxuu_notice as notice")
                .LeftJoin("cxuu_admin_user as user")
                .On("notice.PostUid=user.Id");
            sql.Where("notice.Id =@0", id);
            return await CreateDAO().FirstOrDefaultAsync<ViewNotice>(sql);
        }
    }
}
